package com.exercises;

import com.alibaba.fastjson.JSONArray;

import java.util.*;

class Exercise523 {
    public static void main(String[] args) {
        System.out.println(checkSubarraySum(new int[]{1, 0}, 2));

    }

    public static boolean checkSubarraySum(int[] nums, int k) {
        int legth = nums.length;
        if (legth < 2) return false;

        Map<Integer, Integer> map = new HashMap<>();
        int sum = 0;
        map.put(0, -1);
        for (int i = 0; i < legth; i++) {
            sum = (sum + nums[i]) % k;
            System.out.println(sum);
            if (map.containsKey(sum)) {
                if (i - map.get(sum) >= 2) {
                    return true;
                }
            } else {
                map.put(sum, i);
            }

        }
        return false;
    }

}

